package com.xyht.medicine_management_system.modules.wx.util;

import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class WxUtil {
    @Resource
    private WxMpService wxMpService;

    public WxMpUser getWXMpOAuth2AccessToken(String code) throws Exception {
        WxOAuth2AccessToken result = wxMpService.getOAuth2Service().getAccessToken(code);
        WxMpUser wxMpUser = wxMpService.getUserService().userInfo(result.getOpenId());
        return wxMpUser;
    }
}
